package com.aaa.member.service.impl;

import com.aaa.entity.CouponHistory;
import com.aaa.member.dao.CouponHistoryDao;
import com.aaa.member.service.CouponHistoryService;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author JYH
 * @version 1.0
 * @date 2023/3/2 20:39
 */
@Service
public class CouponHistoryServiceImpl extends ServiceImpl<CouponHistoryDao, CouponHistory> implements CouponHistoryService {

    @Autowired
    private CouponHistoryDao couponHistoryDao;

    @Override
    public Result selectAll(Integer currentPage, Integer pageSize, String cname) {

        PageHelper.startPage(currentPage,pageSize);

        List<CouponHistory> couponHistories = couponHistoryDao.selectAll(cname);
        PageInfo<CouponHistory> pageInfo = new PageInfo<>(couponHistories);
        return new Result(2000,"成功",pageInfo);
    }

    @Override
    public Result selectBymemberId(CouponHistory couponHistory) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        List<CouponHistory> couponHistories = couponHistoryDao.selectByMemberId(couponHistory.getMemberId(),couponHistory.getShopId(),format);
        return new Result(2000,"成功",couponHistories);
    }

    @Override
    public Integer updateState(Integer id,String date) {
        return couponHistoryDao.updateState(id,date);
    }
}
